/**
 * Created by admin on 2017/4/11.
 */
$(function () {
    window.alert = function (src) {
        var htmls = '<div class="alertall">' +
            '<div class="alertTitle">提示</div>' +
            '<div class="alertBody">'+src+'</div>' +
            '<div class="alertOK">确定</div>' +
            '</div>';
        $("#alerts").html(htmls);

        $(".alertOK").click(function(){
            $('.alertall').css("display","none");
        });
    };


    var GetQueryString = function (key) {
        // key为url变量名称
        var urlGets = location.search.substr(1);
        if (urlGets.length > 0) {
            start = urlGets.indexOf(key + '=');
            if (start != -1) {
                start = start + key.length + 1;
                end = urlGets.indexOf('&', start);
                if (end == -1) {
                    end = urlGets.length
                }
                return decodeURIComponent(urlGets.substring(start, end));
            }
        }
        return "";
    };
    $('#infoBtn').click(function () {
        var val = $('#phoneNum').val();
        if(val==""){
            alert('请输入手机号码！');
        }else{
            var reg = /^1[34578]\d{9}$/;
            var a = reg.test(val);
            if (a) {
                var code = GetQueryString("abc");
                $.ajax({
                    type: 'get',
                    url: 'http://new.yytaomeng.com/platform/list/addlist',
                    // url: 'http://192.168.1.128:81/platform/list/addlist',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'jsonp',
                    data: {
                        'phone': val,
                        'code': code
                    },
                    jsonp: 'callback',
                    jsonpCallback: 'successCallback',
                    success: function (data) {

                        if (data.starts == 0) {
                            alert(data.msg);
                        } else {
                            if (data.starts == 3) {
                                alert(data.msg);
                            }
                            window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.zqxq.jiekuanwang";
                        }
                    },
                    error: function (e) {
                        console.log('出错了');
                        console.log(e);
                    }
                });
            } else {
                alert('手机号码输入有误！');
            }
        }

    });
});